Skip to content

Conversation

austinderek
Copy link

The wasm_exec.js file was unnecessarily polluting the global namespace
by adding fs, process, and path to globalThis. These variables are only
used within the importObject functions and can be captured via closure
scope instead.

Changes:

  • Changed globalThis.fs to closure-scoped const fs
  • Changed globalThis.process to closure-scoped const process
  • Changed globalThis.path to closure-scoped const path
  • Updated crypto and performance references to explicitly use globalThis

The IIFE wrapper already provides closure scope, so these variables
don't need to be global. WebAssembly modules can only access what's
in the importObject, and the functions in importObject access these
variables through normal JavaScript scope resolution.

Only globalThis.Go remains global as it's the documented public API
that user code needs to instantiate.

This change:

  • Eliminates potential conflicts with other libraries
  • Follows modern JavaScript best practices
  • Maintains full backwards compatibility
  • Has zero functional impact on existing usage

🔄 This is a mirror of upstream PR golang#75762

@austinderek austinderek force-pushed the master branch 29 times, most recently from c1e6e49 to 5bf50a0 Compare October 7, 2025 05:03
@austinderek austinderek force-pushed the master branch 30 times, most recently from 5bf50a0 to a5f55a4 Compare October 20, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants